<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>天狗商城</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/index.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="container" id="app">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">天狗商城——商品管理</div>
                    <div class="panel-body">
                        <table class="table table-striped table-hover">
                            <tr>
                                <th>序号</th>
                                <th>编号</th>
                                <th>名称</th>
                                <th>单价</th>
                                <th>库存</th>
                                <th>小计</th>
                                <th>操作</th>
                            </tr>

                            <tr v-for="(p,index) in products" :key="p.id">
                                <td>{{index+1}}</td>
                                <td>{{p.productId}}</td>
                                <td>{{p.productName}}</td>
                                <td>{{p.productPrice}}</td>
                                <td>
                                    <button class="btn btn-primary  btn-xs" v-on:click="ys(index,-1,p.productId)" v-bind:disabled="p.productCount<=1?true:false">-</button>
                                    <input type="text" v-model.number="p.productCount" style="width: 50px;">
                                    <button class="btn btn-primary  btn-xs" v-on:click="ys(index,1,p.productId)">+</button>
                                </td>
                                <td>{{ p.productPrice * p.productCount | currency('￥',2)}}</td>
                                <td>
                                    <button type="button" class="btn btn-danger btn-xs" v-on:click="del(p.productId,index)">删除</button>
                                    <button type="button" class="btn btn-primary btn-xs" @click="edit(p)">编辑</button>
                                </td>
                            </tr>

                            <tr v-if="products==null || products.length<=0">
                                <td colspan="7" align="center">数据为空</td>
                            </tr>

                            <tr>
                                <td colspan="7" align="right">总计：{{ total | currency('￥',1) }}</td>
                            </tr>
                        </table>
                    </div>
                </div>


                <div class="panel panel-warning">
                    <div class="panel-heading">商品详细</div>
                    <div class="panel-body" style="position: relative;">
                        <form class="form-horizontal" action="#" method="post" id="frm">
                            <div class="form-group">
                                <label for="productId" class="col-sm-2 control-label">编号</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="productId" name="productId" placeholder="请输入编号" v-bind:value="currProduct.productId" v-bind:readOnly="!isAdd">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="productName" class="col-sm-2 control-label">名称</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="productName" name="productName" placeholder="请输入名称" v-bind:value="currProduct.productName">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="productPrice" class="col-sm-2 control-label">单价</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="productPrice" name="productPrice" placeholder="请输入单价" v-bind:value="currProduct.productPrice">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="productCount" class="col-sm-2 control-label">库存</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="productCount" name="productCount" placeholder="请输入库存" v-bind:value="currProduct.productCount">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="productDesc" class="col-sm-2 control-label">简介</label>
                                <div class="col-sm-6">
                                    <textarea class="form-control" id="productDesc" name="productDesc" rows="3" v-bind:value="currProduct.productDesc"></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="submit" class="btn btn-primary" v-on:click.prevent="save">保存</button>
                                    <button type="submit" class="btn btn-warning" v-on:click.prevent="cls">清空</button>
                                </div>
                            </div>

                        </form>

                        <div class="image">
                            <img v-bind:src="'images/' + (currProduct.productId!=null?currProduct.productId+'.png':'default.jpeg')" onerror="this.src='images/default.jpeg'"/>
                        </div>


                    </div>
                </div>


            </div>
        </div>



    </div>

    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>

    <script src="js/index.js"></script>


</body>

</html>